package springcloud.service.Impl;

import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import springcloud.dao.OrderDao;
import springcloud.domain.Order;
import springcloud.service.AccountService;
import springcloud.service.OrderService;
import springcloud.service.StorageService;

import javax.annotation.Resource;

@Service
@Slf4j
public class OrderServiceImpl implements OrderService {
    @Resource
    private OrderDao orderDao;
    @Resource
    private StorageService storageService;
    @Resource
    private AccountService accountService;

    @Override
    public void create(Order order) {
        log.info("----> 开始新建订单");
        orderDao.create(order);

        log.info("----> 订单微服务开始调用库存，做扣减");
        storageService.decrease(order.getProductId(), order.getCount());
        log.info("----> 订单微服务开始调用库存，做扣减 End");

        log.info("----> 订单微服务开始调用账户，做扣减");
        accountService.decrease(order.getUserId(), order.getMoney());
        log.info("----> 订单微服务开始调用账户，做扣减 End");

        log.info("----> 修改订单的状态开始");
        orderDao.update(order.getUserId(), 0);
        log.info("----> 修改订单的状态结束");

        log.info("----> 下订单结束了");
    }
}

